﻿//
// Created by sail on 19-6-13.
//

#ifndef PROJECT_Link_H
#define PROJECT_Link_H


#include <QtCore/QtGlobal>
#include <QtCore/QObject>

#include <memory>
#include <QTcpSocket>
#include <QByteArray>
#include <QString>
#include <QtNetwork>
#include <queue>
#include <QEvent>

class Messenger: public QObject {
Q_OBJECT
public:
    Messenger();
    ~Messenger();
    void ConnectServer (QString ip,quint16 port);//连接接口

    void DisconnectServer();//断开连接接口

    void write(const QByteArray&);

    bool isOpen();

    void writeAndPromise(const QByteArray& data, int target);

Q_SIGNALS:
    void onConnectServer();

    void onDisconnectServer();

    void onChannel(std::vector<float>&);

private:
    std::shared_ptr<QTcpSocket>_tcpSocket;

    int ByteToInt(const QByteArray& originalM);

    union dataTransform
    {
        short num;
        unsigned char data[2];
    };

    int _FPGAData;
};
#endif //PROJECT_Link_H
